package com.mobi.Survey.map;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;

public class AppSettingsScreen extends MyTab {

	private ContainerWeb webContainer;
	private View containerParent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

	}

	@Override
	protected void initUiVars() {
		containerParent = findViewById(R.id.containerSettings);
		webContainer = new ContainerWeb(this);
		webContainer.setupViews();
		ToggleButton notify = (ToggleButton) findViewById(R.id.toggleNotification);

		if (notification(this)) {
			notify.setChecked(true);
		} else {
			notify.setChecked(false);
		}
		notify.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				setNotification(isChecked, AppSettingsScreen.this);
			}
		});
	}

	public final void makeVisible() {
		containerParent.setVisibility(View.VISIBLE);
	}

	public final void makeGone() {
		containerParent.setVisibility(View.GONE);
	}

	@Override
	protected int getLayoutId() {

		return R.layout.app_settings;
	}
 

	public void onClick(View v) {
		if (v.getId() == R.id.btnNotification) {

		} else if (v.getId() == R.id.btnAppReview) {

			try {
				final String appPackageName = getPackageName();
				startActivity(new Intent(Intent.ACTION_VIEW,
						Uri.parse(getResources().getString(R.string.app_store,
								appPackageName))));
			} catch (android.content.ActivityNotFoundException anfe) {

			}

		} else if (v.getId() == R.id.btnHelp) {

			this.makeGone();
			this.webContainer.makeVisible();
			this.webContainer.open(getResources().getString(
					R.string.biz_contactus));

		} else if (v.getId() == R.id.btnPolicy) {

			this.makeGone();
			this.webContainer.makeVisible();

			this.webContainer.open(getResources().getString(R.string.privacy));

		}
	}

	private boolean isVisible() {
		return this.containerParent.getVisibility() == View.VISIBLE;
	}

	@Override
	public void onBackPressed() {

		if (!isVisible()) {
			this.makeVisible();
			this.webContainer.open("about:blank");
			this.webContainer.makeGone();
			return;
		}

		super.onBackPressed();
	}

}
